import tkinter as tk
from tkinter import filedialog
import re
import pyperclip
#打开文件
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(filetypes=[('output files', '.out')])
with open(file_path, 'r') as f:
    lines=f.readlines()

def readMO(text):
    HOMOs=[]
    LUMOs=[]
    for HOMO in text:
        if "Alpha  occ. eigenvalues --" in HOMO:
            HOMOs.append(HOMO)
    for LUMO in text:
        if 'Alpha virt. eigenvalues --' in LUMO:
            LUMOs.append(LUMO)
    goal_HOMO=re.findall(r"\-?\d+\.?\d*",HOMOs[-1])[-1]
    goal_LUMO=re.findall(r"\-?\d+\.?\d*",LUMOs[0])[0]
    print('第一行为LUMO 第二行为HOMO 已复制到剪贴板' )
    print('LUMO：'+goal_LUMO+'Ha')
    print('HOMO：'+goal_HOMO+'Ha')
    pyperclip.copy(goal_LUMO+'\n'+goal_HOMO)
    #input('按回车键退出')
    return goal_LUMO,goal_HOMO

readMO(lines)